<template>
	<view id="page">
		<nav-bar :navH="navH" :isTabar="true" :isHome="false" :pageName="title"></nav-bar>
		<view class="mine">
			<view>
				<image :src="userInfo.img" lazy-load="true" class="logo" @error="imgError" v-if="userInfo.img"></image>
				<image src="../../static/avatars_default.png" lazy-load="true" class="logo" v-else></image>
				<view class="info">
					<text class="name">{{userInfo.name}}</text><image src='../../static/4.png' mode="widthFix" lazy-load="true" class="vip" v-if="userInfo.grade == 1"></image>
					<view class="bt">
						<navigator url="../profile/index" hover-class="none" class="t l">个人资料</navigator>
						<navigator url="../qiandao/index" hover-class="none" class="t m">签到</navigator>
						<navigator url="../set/index" hover-class="none" class="t r"><image src="../../static/33.png" mode="widthFix" lazy-load="true"></image></navigator>
					</view>
				</view>
			</view>
			<view class="flex">
				<view class="flex-i">关注<text>{{userInfo.guan}}</text></view>
				<view class="flex-i">粉丝<text>{{userInfo.fans}}</text></view>
				<view class="flex-i">收藏<text>{{userInfo.cang}}</text></view>
			</view>
		</view>
		<!-- 图文列表 -->
	    <view class="classify clearfloat">
			<view :class="['class-i', isOn === 0 ? 'on' : '']" @click='switchMenu(0)'>全部</view>
			<view :class="['class-i', isOn === 1 ? 'on' : '']" @click='switchMenu(1)'>视频({{spnum}})</view>
			<view :class="['class-i', isOn === 2 ? 'on' : '']" @click='switchMenu(2)'>图文({{zxnum}})</view>
			<view :class="['class-i', isOn === 3 ? 'on' : '']" @click='switchMenu(3)'>收藏({{scnum}})</view>
	    </view>
		<!-- 图文列表 -->
		<!-- <pic-txt :lists="lists" v-if="hasRes"></pic-txt>
		<view class="nocont" v-else>暂无内容</view> -->
		<view class="nomore" v-if="isLoad"><image src='../../static/nomore_img.png' mode="widthFix"></image><text>没有更多了~</text></view>
		<tab-bar :selected="4"></tab-bar>
	</view>
</template>

<script>
	// import PicTxt from '../../components/pictxt/index.vue'
	import app from '../../common/index.js'
	export default {
		data() {
			return {
				title: '我的',
				navH: null,
				userInfo: {},
				isOn: 0,
				spnum: '',
				zxnum: '',
				scnum: '',
				hasRes: true,
				isLoad: false,
				page: 1,
				size: 10,
				lists: [],
				handedData: [[],[],[],[]],  // 分类过的数据
			}
		},
		onLoad(options) {
			this.navH = this.$store.state.navHeight;
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getPicTxt();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.lists = [];
			this.handedData = [[],[],[],[]];
			// 获取本地用户信息
			this.userInfo = uni.getStorageSync('uinfo');
			this.getPicTxt();
			uni.stopPullDownRefresh();
		},
		/**
		 * @des 上划加载
		 */
		onReachBottom() {
			if(!this.isLoad) {
				this.page = this.page +1;
				this.getPicTxt();
			}
		},
		// 分享转发
		onShareAppMessage() {
			return {
				title: '爱美指南针',
				path: 'pages/index/index',
			}
		},
		components: {
			// PicTxt,
		},
		methods: {
			/**
			 * @des 获取资讯列表
			 */
			getPicTxt() {
				app.request({
					url: 'entry/wxapp/zxlist',
					data: {
						user_id: this.userInfo.id,
						page: this.page,
						pagesize: this.size,
					}
				}, (ret) => {
					let d = ret.data, totalArr = this.handedData, len = d.data.length;
					this.spnum = d.video;
					this.zxnum = d.tuwen;
					this.scnum = d.cang;
					if (d.total > 0) {
						this.hasRes = true;
						this.isLoad = len < this.size ? true : false;
						d.data.forEach((item, index) => {  // 此处做数据分类处理
							totalArr[0].push(item);
							if(item.is_video == '1') {
								totalArr[1].push(item);
							}else if(item.is_cang == '1') {
								totalArr[3].push(item);
							}else {
								totalArr[2].push(item);
							}
							
						})
						this.handedData = totalArr;
						this.switchMenu(this.isOn);
					} else {
						this.hasRes = false;
					}
				})
			},
			/**
			 * @des 切换菜单
			 */
			switchMenu(i) {
				this.isOn = i;
				this.lists = this.handedData[i];
			}
		}
	}
</script>

<style>
	.flex {width: 100%; margin: 30upx 0 20upx;}
	.flex .flex-i {width: 33.3%; padding: 0 10upx; border-right: 1px solid #eee; font-size: 24upx; color: #888;}
	.flex .flex-i:last-child {border: 0;}
	.flex .flex-i text {display: inline-block; padding-left: 10upx;}
	.mine {padding: 30upx; border-bottom: 1px solid #eee; background-color: #fff;}
	.mine .logo {width: 160upx; height: 160upx; border-radius: 100%; float: left;}
	.mine .info {height: 160upx; margin-left: 200upx; text-align: left;}
	.mine .info .name {display: inline-block; margin: 10upx 30upx 10upx 10upx; font-size: 32upx;}
	.mine .info .vip {width: 38upx; z-index: 99;}
	.mine .info .bt {display: flex; text-align: center; margin-top: 30upx;}
	.mine .info .bt .t {height: 50upx; margin: 0 10upx; border-radius: 50upx; line-height: 48upx;}
	.mine .info .bt .t.l {flex: 5;  background-color: #82d7d0; color: #fff;}
	.mine .info .bt .t.m {flex: 4; border: 1px solid #82D7D0; color: #82D7D0;}
	.mine .info .bt .t.r {flex: 2; line-height: 46upx; border: 1px solid #eee;}
	.mine .info .bt .r image {width: 35upx;}
	/** 图文分类菜单 */
	.classify {width: 100%; padding: 0 20upx; background-color: #fff;}
	.classify .class-i {float: left; margin: 0 20upx; padding: 20upx 10upx; line-height: 1; font-size: 30rpx; color: #888;}
	.classify .class-i.on {color: #82d7d0; border-bottom: 2px solid #82d7d0;}
</style>
